package com.math;

public class NewQuickSort {
    public static void main(String[] args) {
        int[] qList = {3, 1, 2, 7, 5};
        quickSort(qList, 0, qList.length - 1);
        for (int i = 0; i < qList.length; i++) {
            System.out.println(qList[i]);
        }
    }
    //  快速排序，双指针排序
    private static void quickSort(int[] list, int left, int right) {
        if (left >= right) { return; }
        int x = list[left];
        int i = left - 1;
        int j = right + 1;
        while (i < j) {
            do { i++; } while (list[i] < x);
            do { j--; } while (list[j] > x);
            if (i < j) {
                int temp = list[i];
                list[i] = list[j];
                list[j] = temp;
            }
        }
        quickSort(list, left, j);
        quickSort(list, j + 1, right);
    }
}
